package com.lazyJr.test.propertise;
import java.io.*;
import java.util.Properties;

/**
 * /p需要InputStream对象进行读取文件，而获取InputStream有多种方法：
 //1、通过绝对路径:InputStream is=new FileInputStream(filePath);
 //2、通过Class.getResourceAsStream(path);
 //3、通过ClassLoader.getResourceAsStream(path);
 *
 *
 * Created by liuyangfx on 16-3-18.
 */
public class PropertiseTest {

    public String readFromPropertise(String filename) throws IOException {
        Properties properties = new Properties();
        InputStream inputStream;
//1、这个要用绝对路径
        File file = new File(filename);
        FileInputStream fileInputStream = new FileInputStream(file);
        properties.load(fileInputStream);

        //暂没有发现为什么找不到
//        inputStream = this.getClass().getResourceAsStream("test");
//        properties.load(inputStream);
        String url = properties.getProperty("url");
        return url;
    }

    public static void main(String[] args) throws IOException {
        PropertiseTest test = new PropertiseTest();
        String filename = "/data/lyown/codeTest/Test/src/main/java/com.lazyJr.test/propertise/test";
        String url = test.readFromPropertise(filename);
        System.out.println(url);
    }
}
